
package com.zsrt.day20170424.file01;


import java.io.File;
import java.io.FileInputStream;

import org.junit.Test;


public class InputStream {

	@Test
	public void readTest() throws Exception {
		
		//1.侦查   一次只能打印一个字节
		File file = new File("E:/lianxi/lian.txt");
		
		FileInputStream input = new FileInputStream(file);
		
		int i = input.read();
		
		System.out.println(i);
		
		input.close();
	}
	
	/**
	 * 一次一批
	 * @throws Exception
	 */
	@Test
	public void readTest01() throws Exception {
		File file = new File("E:/lianxi/lian.txt");
		
		FileInputStream input = new FileInputStream(file);
		
		int result= input.read();
		while( result !=-1){
			
			//把ASCII码转换成字符
			System.out.print((char)result);
			
			result = input.read();
			
		}
		input.close();
	}
	
	
	@Test
	public void test03() throws Exception {
		//绝对路径
		File file = new File("E:/lianxi/lian.txt");
		
		FileInputStream input = new FileInputStream(file);
		
		byte[] b = new byte[4];
		
		int len = -1;
		
		
		while((len = input.read(b)) != -1){
			for(int index = 0;index<len;index++){
				
				System.out.println((char)b[index]);
			}
			
			//len = input.read(b);
		}
		input.close();
	}
	
	
}
